1 Public Class frmadduser
2 Dim strERR As String
3 Dim strNOERR As String
4 Private Sub cmdcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdcancel.Click
5 Close()
6 End Sub
7
8 Private Sub cmdupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupdate.Click
9 strERR = "Please complete the following requirements!" & Chr(10) & "-----------------------------"
10 strNOERR = strERR
11 If txtfname.Text = "" Then
12 strERR = strERR & Chr(10) & " Username"
13 End If
14 If txtlname.Text = "" Then
15 strERR = strERR & Chr(10) & " Lastname"
16 End If
17 If txtmname.Text = "" Then
18 strERR = strERR & Chr(10) & " Middlename"
19 End If
20 If txtaddress.Text = "" Then
21 strERR = strERR & Chr(10) & " Address"
22 End If
23 If txtcontact.Text = "" Then
24 strERR = strERR & Chr(10) & "Mobile / Phone "
25 End If
26 If txtusername.Text = "" Then
27 strERR = strERR & Chr(10) & " Username "
28 End If
29 If Len(txtpassword.Text) < 6 Then
30 strERR = strERR & Chr(10) & "Password Must Be At least 6 Characters"
31 End If
32 If txtpassword.Text = "" Then
33 strERR = strERR & Chr(10) & " Password "
34 End If
35
36 If cmbaccnttype.Text = "" Then
37 strERR = strERR & Chr(10) & " Account Type "
38 End If
39 If txtpassword.Text <> txtconfirm.Text Then
40 strERR = strERR & Chr(10) & " Password not match "
41 End If
42 If strNOERR <> strERR Then
43 MsgBox(strERR, MsgBoxStyle.Information, "Sales and Inventory")
44 Exit Sub
45 End If
46
47 If Me.Text = "Edit User Account" Then
48 If UCase(xUser_Access) = UCase("Administrator") Then
49 sqlSTR = "UPDATE tbl_users SET username ='" & txtusername.Text & "', " _
50 & "userpass='" & txtpassword.Text & "', " _
51 & "access_type='" & cmbaccnttype.Text & "', " _
52 & "lastname='" & txtlname.Text & "', " _
53 & "firstname='" & txtfname.Text & "', " _
54 & "middlename='" & txtmname.Text & "', " _
55 & "address='" & txtaddress.Text & "', " _
56 & "contact='" & txtcontact.Text & "', " _
57 & "local_number ='" & txtlocal.Text & "' WHERE user_id =" & FrmSysUser.lstusers.FocusedItem.Text
58 Else
59 sqlSTR = "UPDATE tbl_users SET username ='" & txtusername.Text & "', " _
60 & "userpass='" & txtpassword.Text & "', " _
61 & "access_type='" & cmbaccnttype.Text & "', " _
62 & "lastname='" & txtlname.Text & "', " _
63 & "firstname='" & txtfname.Text & "', " _
64 & "middlename='" & txtmname.Text & "', " _
65 & "address='" & txtaddress.Text & "', " _
66 & "contact='" & txtcontact.Text & "', " _
67 & "local_number ='" & txtlocal.Text & "' WHERE user_id =" & xUser_ID
68 End If
69
70 ExecuteSQLQuery(sqlSTR)
71 Audit_Trail(xUser_ID, TimeOfDay, "Edit User Account ")
72 Else
73 sqlSTR = "INSERT INTO tbl_users (username, userpass, access_type, lastname, firstname, middlename, address, contact, local_number) VALUES('" & txtusername.Text & "', " _
74 & "'" & txtpassword.Text & "', " _
75 & "'" & cmbaccnttype.Text & "', " _
76 & "'" & txtlname.Text & "', " _
77 & "'" & txtfname.Text & "', " _
78 & "'" & txtmname.Text & "', " _
79 & "'" & txtaddress.Text & "', " _
80 & "'" & txtcontact.Text & "', " _
81 & "'" & txtlocal.Text & "')"
82 ExecuteSQLQuery(sqlSTR)
83 Audit_Trail(xUser_ID, TimeOfDay, "Add New User Account ")
84 End If
85
86 'ExecuteSQLQuery(sqlSTR)
87 MsgBox("Record Successfuly Update! ", MsgBoxStyle.Information)
88 FillListView(ExecuteSQLQuery("select user_id as 'Account No', Username as 'Username', Access_type as 'Access Type' FROM tbl_users"), FrmSysUser.lstusers, 1)
89 Me.Close()
90 End Sub
91
92 Private Sub frmadduser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
93 txtlname.Text = ""
94 txtfname.Text = ""
95 txtmname.Text = ""
96 txtaddress.Text = ""
97 txtcontact.Text = ""
98 txtlocal.Text = ""
99 If Me.Text = "Edit User Account" Then
100 'FrmSysUser.lstusers.Select()
101 If UCase(xUser_Access) = UCase("Administrator") Then
102 FrmSysUser.lstusers.Focus()
103 sqlSTR = "SELECT * FROM tbl_users WHERE user_ID =" & FrmSysUser.lstusers.FocusedItem.Text
104 txtlname.Enabled = True
105 txtfname.Enabled = True
106 txtmname.Enabled = True
107 txtaddress.Enabled = True
108 txtcontact.Enabled = True
109 txtlocal.Enabled = True
110 txtusername.Enabled = True
111 txtpassword.Enabled = True
112 txtconfirm.Enabled = True
113 cmbaccnttype.Enabled = True
114 Else
115 sqlSTR = "SELECT * FROM tbl_users WHERE user_ID =" & xUser_ID
116 txtlname.Enabled = False
117 txtfname.Enabled = False
118 txtmname.Enabled = False
119 txtaddress.Enabled = True
120 txtcontact.Enabled = True
121 txtlocal.Enabled = False
122 txtusername.Enabled = False
123 txtpassword.Enabled = True
124 txtconfirm.Enabled = True
125 cmbaccnttype.Enabled = False
126 End If
127 ExecuteSQLQuery(sqlSTR)
128 'MsgBox(sqlDT.Rows(0)("username"))
129 With sqlDT
130 If .Rows.Count > 0 Then
131 'MsgBox(sqlDT.Rows(0)("lastname"))
132 txtlname.Text = .Rows(0)("lastname")
133 txtfname.Text = .Rows(0)("firstname")
134 txtmname.Text = .Rows(0)("middlename")
135 txtaddress.Text = .Rows(0)("address")
136 txtcontact.Text = .Rows(0)("contact")
137 txtlocal.Text = .Rows(0)("local_number").ToString
138 txtusername.Text = .Rows(0)("username")
139 txtpassword.Text = .Rows(0)("userpass")
140 txtconfirm.Text = .Rows(0)("userpass")
141 cmbaccnttype.Text = .Rows(0)("access_type")
142 End If
143 End With
144 End If
145 End Sub
146
147 Private Sub txtlname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtlname.TextChanged
148 'txtusername.Text = txtlname.Text
149 txtlname.Text = filter_Special_Char(str_Filter(txtlname, 65, 122, 32, 50))
150 txtusername.Text = txtlname.Text
151 End Sub
152
153 Private Sub txtcontact_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtcontact.TextChanged
154 txtcontact.Text = str_Filter(txtcontact, 48, 57, 0, 0)
155 End Sub
156
157 Private Sub txtfname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtfname.TextChanged
158 txtfname.Text = filter_Special_Char(str_Filter(txtfname, 65, 122, 32, 50))
159 End Sub
160
161 Private Sub txtmname_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtmname.TextChanged
162 txtmname.Text = filter_Special_Char(str_Filter(txtmname, 65, 122, 32, 50))
163 End Sub
164
165 Private Sub txtlocal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtlocal.TextChanged
166 txtlocal.Text = str_Filter(txtlocal, 48, 57, 0, 0)
167 End Sub
168 End Class